/*
 * @lc app=leetcode.cn id=5 lang=cpp
 *
 * [5] 最长回文子串
 */

// @lc code=start
class Solution {
public:
    string longest(string &s,int left,int right)
    {
        while(left >= 0 && right <=s.size() && s[left] == s[right] )
        {
            left--;
            right++;
        }
        return s.substr(left+1,right-left-1);
    }

    string longestPalindrome(string s) {
        string max;
        for(int i = 0 ; i < s.size() ; i++)
        {
            string str1 = longest(s,i,i);
            string str2 = longest(s,i,i+1);
            max = str1.size()>max.size()?str1:max;
            max = str2.size()>max.size()?str2:max;
        }
        return max;
    }
};
// @lc code=end

